﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.FarmingInformation
{
    public class VaccineCreateHandler:IRequestHandler<VaccineCreateCommond, Rulst>
    {

        private readonly IbaseRpository<VaccineMess> _Vaccinemess;
        private readonly IbaseRpository<breedMess> _breedMess;
        public VaccineCreateHandler(IbaseRpository<VaccineMess> vaccinemess, IbaseRpository<breedMess> _breedMess)
        {
            _Vaccinemess = vaccinemess;
            this._breedMess = _breedMess;
        }

        public async Task<Rulst> Handle(VaccineCreateCommond request, CancellationToken cancellationToken)
        {


            var query = new Rulst() { Code = (int)Reult.success };

            ///保健信息添加
            var list = _Vaccinemess.Add(request.VaccineMess);

            var gh = _Vaccinemess.Query().Where(x => x.HealThcareMode == request.VaccineMess.HealThcareMode && x.HealthcareMethod == request.VaccineMess.HealthcareMethod &&x.RearDay==request.VaccineMess.RearDay).FirstOrDefault();

            var GETBreed = _breedMess.Query().Where(x => x.ProDuctionBasicid == request.ProDuctionBasicid).FirstOrDefault();

            if(gh!=null&&GETBreed!=null)
            {
                GETBreed.Vaccineid = gh.VaccioneMessid;
                _breedMess.update(GETBreed);
            }


            return query;
          

        }
    }
}
